<?
function printr($array)
{
	return '<pre>'.print_r($array, true).'</pre>';
}

function diepr($array)
{
	die(printr($array));
}

function dievd($array)
{
	die(var_export($array, true));
}

function dieJSON($array)
{
	die(json_encode($array));
}

function is_arr($array)
{
	return (!empty($array) && is_array($array));
}

function setKeys($array, $key)
{
	$exp = array();
	foreach ($array as $val)
		$exp[(is_array($val)?$val[$key]:$val->$key)] = $val;
	return $exp;
}

function printDate($now, $time = false)
{
	return date($time?'d.m.Y H:i:s':'d.m.Y', $now);
}

function rootDir()
{
	return $_SERVER['DOCUMENT_ROOT'].'/';
}

function extractFieldFromDataArray($dataArray, $field, $nulls = true)
{
	if (!is_array($dataArray) || !sizeof($dataArray)) return array();
	$res = array();
	foreach ($dataArray as $dataItem)
	{
		if (is_object($dataItem)) 
			$dataItem = (array) $dataItem;
		if (isset($dataItem[$field]))
			if ($nulls || (abs($dataItem[$field]) != 0))
				$res[] = $dataItem[$field];
	}
	return $res;
}

function htmlEscape($str)
{
	return str_replace(
		array('"', "'", '<', '>', ':'),
		array('&quot;', '&prime;', '&lt;', '&gt;', '&#058;'),
		trim($str));
}

function echobr($value = '')
{
	echo $value.'<br>';
}

function getTemplate()
{
	$CI =& get_instance();
	return $CI->main_model->getTemplate();
}